package com.huaxi.ddgw.manager.controller;

import com.huaxi.ddgw.manager.service.OrderInfoService;
import com.huaxi.ddgw.model.dto.h5.OrderInfoDto;
import com.huaxi.ddgw.model.dto.order.OrderStatisticsDto;
import com.huaxi.ddgw.model.entity.order.OrderInfo;
import com.huaxi.ddgw.model.vo.common.Result;
import com.huaxi.ddgw.model.vo.common.ResultCodeEnum;
import com.huaxi.ddgw.model.vo.order.OrderStatisticsVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value="/admin/order/orderInfo")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    //返回统计数据
    @GetMapping("/getOrderStatisticsData")
    public Result getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
        OrderStatisticsVo orderStatisticsVo = orderInfoService.getOrderStatisticsData(orderStatisticsDto);
        return Result.build(orderStatisticsVo, ResultCodeEnum.SUCCESS);
    }

    //订单列表
    @GetMapping("/findByPage/{page}/{limit}")
    public Result findByPage(@PathVariable Integer page,
                             @PathVariable Integer limit,
                             OrderInfoDto orderInfoDto) {
        if (page == null || limit == null) {
            page = 1;
            limit = 5;
        }
        PageInfo<OrderInfo> pageInfo = orderInfoService.findByPage(page, limit, orderInfoDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    //订单详情
    @GetMapping("/findOrderInfo/{orderNo}")
    public Result findOrderInfo(@PathVariable String orderNo) {
        List<OrderInfo> orderInfoList = orderInfoService.findOrderInfo(orderNo);
        PageInfo<OrderInfo> pageInfo = new PageInfo<>(orderInfoList);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
}
